package com.swt.gap.controller;

import com.swt.gap.model.entity.AchievementClass;
import com.swt.gap.model.entity.AchievementTemplate;
import com.swt.gap.service.AchievementTemplateService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sx
 */
@Api(tags = "501. 战果模板")
@RestController
@RequestMapping("/achievement/template")
@Slf4j
public class AchievementTemplateController {

    private final AchievementTemplateService achievementTemplateService;

    public AchievementTemplateController(AchievementTemplateService achievementTemplateService) {
        this.achievementTemplateService = achievementTemplateService;
    }


    @PostMapping
    @ApiOperation(value = "新建模板", notes = "新建模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "record", dataType = "AchievementTemplate",paramType = "body")
    })
    @ApiResponses({@ApiResponse(code = 201, message = "created", response = Integer.class)})
    public ResponseEntity<Integer> addAchievementTemplate(@RequestBody AchievementTemplate record){
        return ResponseEntity.ok(achievementTemplateService.addAchievementTemplate(record));
    }

    @GetMapping("/{achievementTemplateId}")
    @ApiOperation(value = "根据id获取模板", notes = "根据id获取模板")
    @ApiImplicitParam(name = "achievementTemplateId", dataType = "int",paramType = "path", value = "战果模板Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = AchievementTemplate.class)})
    public ResponseEntity<AchievementTemplate> getAchievementTemplateById(@PathVariable Integer achievementTemplateId){
        return ResponseEntity.ok(achievementTemplateService.getAchievementTemplateById(achievementTemplateId));
    }

    @GetMapping
    @ApiOperation(value = "获取模板列表", notes = "获取模板列表")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = AchievementTemplate.class, responseContainer = "List")})
    public ResponseEntity<List<AchievementTemplate>> listAllAchievementClass(){
        return ResponseEntity.ok(achievementTemplateService.listAll());
    }

    @PutMapping("/{achievementTemplateId}")
    @ApiOperation(value = "修改模板", notes = "修改模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "achievementTemplateId", dataType = "int",paramType = "path", value = "战果模板Id"),
            @ApiImplicitParam(name = "record", dataType = "AchievementTemplate",paramType = "body")
    })

    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> updateAchievementTemplateById(@PathVariable Integer achievementTemplateId,
                                                          @RequestBody AchievementTemplate record){
        record.setTemplateId(achievementTemplateId);
        return ResponseEntity.ok(achievementTemplateService.updateAchievementTemplateById(record));
    }

    @DeleteMapping("/{achievementTemplateId}")
    @ApiOperation(value = "删除模板", notes = "删除模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "achievementTemplateId", dataType = "int",paramType = "path", value = "战果模板Id")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> deleteAchievementTemplateById(@PathVariable Integer achievementTemplateId){
        return ResponseEntity.ok(achievementTemplateService.deleteAchievementTemplateById(achievementTemplateId));
    }

}
